import axios from 'axios'
import { Message } from 'element-ui'
import store from '@/store'

// create an axios instance
const service = axios.create({
  // 从环境变量读取的基地址
  baseURL: process.env.VUE_APP_BASE_API,
  // withCredentials: true, // send cookies when cross-domain requests

  // 设置超时时间，也就是说一个请求超过5秒还没响应就直接失败
  timeout: 5000
})

// 请求拦截
service.interceptors.request.use(config => {
  return config
}, err => {
  return Promise.reject(err)
})

// 响应拦截
service.interceptors.response.use(response => {
  // 做剥离
  return response.data
}, err => {
  return Promise.reject(err)
})

export default service
